<?php
/* tblCalendar */
class tblCalendar extends NocForm
	{
		protected $_ID                 = array();
		protected $_EventDate                 = array();
		protected $_StartTime                 = array();
		protected $_EndTime                 = array();
		protected $_Subject                 = array();
		protected $_Details                 = array();
		protected $_Staff                 = array();
		protected $_ExtraField1                 = array();
		protected $_ExtraField2                 = array();

		function __construct()
		{
			parent::__construct();
			$this->getRow();
		}
		public function get_ID()
		{
				return  $this->_get_IDValue();
		}

		private function _get_IDValue()
		{
			if(isset($this->_ID['value']))
				return $this->_ID['value'];
			else
				return false;
		}

		public function get_EventDate()
		{
				return  $this->_get_EventDateValue();
		}

		private function _get_EventDateValue()
		{
			if(isset($this->_EventDate['value']))
				return $this->_EventDate['value'];
			else
				return false;
		}

		public function get_StartTime()
		{
				return  $this->_get_StartTimeValue();
		}

		private function _get_StartTimeValue()
		{
			if(isset($this->_StartTime['value']))
				return $this->_StartTime['value'];
			else
				return false;
		}

		public function get_EndTime()
		{
				return  $this->_get_EndTimeValue();
		}

		private function _get_EndTimeValue()
		{
			if(isset($this->_EndTime['value']))
				return $this->_EndTime['value'];
			else
				return false;
		}

		public function get_Subject()
		{
				return  $this->_get_SubjectValue();
		}

		private function _get_SubjectValue()
		{
			if(isset($this->_Subject['value']))
				return $this->_Subject['value'];
			else
				return false;
		}

		public function get_Details()
		{
				return  $this->_get_DetailsValue();
		}

		private function _get_DetailsValue()
		{
			if(isset($this->_Details['value']))
				return $this->_Details['value'];
			else
				return false;
		}

		public function get_Staff()
		{
				return  $this->_get_StaffValue();
		}

		private function _get_StaffValue()
		{
			if(isset($this->_Staff['value']))
				return $this->_Staff['value'];
			else
				return false;
		}

		public function get_ExtraField1()
		{
				return  $this->_get_ExtraField1Value();
		}

		private function _get_ExtraField1Value()
		{
			if(isset($this->_ExtraField1['value']))
				return $this->_ExtraField1['value'];
			else
				return false;
		}

		public function get_ExtraField2()
		{
				return  $this->_get_ExtraField2Value();
		}

		private function _get_ExtraField2Value()
		{
			if(isset($this->_ExtraField2['value']))
				return $this->_ExtraField2['value'];
			else
				return false;
		}


		public function set_IDValue($strID)
		{
			if($this->validateInput("validatexxxxx", $strID, "ID "))
					return($this->_setNewValue($this->_ID, $strID));
			else
					return false;
		}

		public function set_EventDateValue($strEventDate)
		{
			if($this->validateInput("validatexxxxx", $strEventDate, "EventDate "))
					return($this->_setNewValue($this->_EventDate, $strEventDate));
			else
					return false;
		}

		public function set_StartTimeValue($strStartTime)
		{
			if($this->validateInput("validatexxxxx", $strStartTime, "StartTime "))
					return($this->_setNewValue($this->_StartTime, $strStartTime));
			else
					return false;
		}

		public function set_EndTimeValue($strEndTime)
		{
			if($this->validateInput("validatexxxxx", $strEndTime, "EndTime "))
					return($this->_setNewValue($this->_EndTime, $strEndTime));
			else
					return false;
		}

		public function set_SubjectValue($strSubject)
		{
			if($this->validateInput("validatexxxxx", $strSubject, "Subject "))
					return($this->_setNewValue($this->_Subject, $strSubject));
			else
					return false;
		}

		public function set_DetailsValue($strDetails)
		{
			if($this->validateInput("validatexxxxx", $strDetails, "Details "))
					return($this->_setNewValue($this->_Details, $strDetails));
			else
					return false;
		}

		public function set_StaffValue($strStaff)
		{
			if($this->validateInput("validatexxxxx", $strStaff, "Staff "))
					return($this->_setNewValue($this->_Staff, $strStaff));
			else
					return false;
		}

		public function set_ExtraField1Value($strExtraField1)
		{
			if($this->validateInput("validatexxxxx", $strExtraField1, "ExtraField1 "))
					return($this->_setNewValue($this->_ExtraField1, $strExtraField1));
			else
					return false;
		}

		public function set_ExtraField2Value($strExtraField2)
		{
			if($this->validateInput("validatexxxxx", $strExtraField2, "ExtraField2 "))
					return($this->_setNewValue($this->_ExtraField2, $strExtraField2));
			else
					return false;
		}
		public function update()
		{
			if($this->_boFailedValidation)
					return false;
					$strErrorMsg = "";
					$strSuccessMsg = "";
			if($this->get_ID() == "")
					return $this->_setFailScreens("Update aborted no record selected.", true);

			$strJoin = "";
			$strSql = "UPDATE tblCalendar
					SET ";
					if($this->_ID['updated'])
					{
						$strSql .= $strJoin." ID = '".$this->_ID['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_ID['oldvalue']."' to '".$this->_ID['value']."'<br/>";
						$strErrorMsg .= "ID not updated<br/>";					}

					if($this->_EventDate['updated'])
					{
						$strSql .= $strJoin." EventDate = '".$this->_EventDate['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_EventDate['oldvalue']."' to '".$this->_EventDate['value']."'<br/>";
						$strErrorMsg .= "EventDate not updated<br/>";					}

					if($this->_StartTime['updated'])
					{
						$strSql .= $strJoin." StartTime = '".$this->_StartTime['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_StartTime['oldvalue']."' to '".$this->_StartTime['value']."'<br/>";
						$strErrorMsg .= "StartTime not updated<br/>";					}

					if($this->_EndTime['updated'])
					{
						$strSql .= $strJoin." EndTime = '".$this->_EndTime['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_EndTime['oldvalue']."' to '".$this->_EndTime['value']."'<br/>";
						$strErrorMsg .= "EndTime not updated<br/>";					}

					if($this->_Subject['updated'])
					{
						$strSql .= $strJoin." Subject = '".$this->_Subject['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Subject['oldvalue']."' to '".$this->_Subject['value']."'<br/>";
						$strErrorMsg .= "Subject not updated<br/>";					}

					if($this->_Details['updated'])
					{
						$strSql .= $strJoin." Details = '".$this->_Details['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Details['oldvalue']."' to '".$this->_Details['value']."'<br/>";
						$strErrorMsg .= "Details not updated<br/>";					}

					if($this->_Staff['updated'])
					{
						$strSql .= $strJoin." Staff = '".$this->_Staff['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Staff['oldvalue']."' to '".$this->_Staff['value']."'<br/>";
						$strErrorMsg .= "Staff not updated<br/>";					}

					if($this->_ExtraField1['updated'])
					{
						$strSql .= $strJoin." ExtraField1 = '".$this->_ExtraField1['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_ExtraField1['oldvalue']."' to '".$this->_ExtraField1['value']."'<br/>";
						$strErrorMsg .= "ExtraField1 not updated<br/>";					}

					if($this->_ExtraField2['updated'])
					{
						$strSql .= $strJoin." ExtraField2 = '".$this->_ExtraField2['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_ExtraField2['oldvalue']."' to '".$this->_ExtraField2['value']."'<br/>";
						$strErrorMsg .= "ExtraField2 not updated<br/>";					}

			$strSql .= "WHERE ID = ". $this->get_ID();
			//Only execute sql if there is something to update.
			if($strJoin == ",")
			{
				//echo nl2br($strSql);
				if(!($DatabaseResult = mysql_query($strSql)))
					return $this->_setFailScreens($strErrorMsg);
				$GLOBALS['arrSuccessMessages'][] = $strSuccessMsg;
			}else
				$GLOBALS['arrSuccessMessages'][] = "No data hasn't changed so no updates made.";
			return(TRUE);
		}
			public function delete_tblCalendar()
			{
				if($this->get_IDValue() == "")
					return $this->_setFailScreens("Delete aborted no record selected.", true);
				
		
				/* Deleted port forward from agg */
				$strSql =   "DELETE FROM tblCalendar
		   					  WHERE ID		= ".$this->get_IDValue();
		
				$qryDeletetblCalendar = new MySqlResults($strSql);
		
				if(!$qryDeletetblCalendar->result)
					return ($this->_setFailScreens("An error occurred while trying to delete database entry."));
		
		
				$GLOBALS['arrSuccessMessages'][] = " has been removed";
				return true;
			}
		public function insert_tblCalendar()
		{
			/* Check that all required fields have been set */
			if (!($this->_validateAllFieldsSet()))
			{
				return ($this->_setFailScreens("Fields required to add a new record haven't all been set", true));
			}
			
			$strSql =   "INSERT INTO tblCalendar
						  (
		 	EventDate

		, 	StartTime

		, 	EndTime

		, 	Subject

		, 	Details

		, 	Staff

		, 	ExtraField1

		, 	ExtraField2
)VALUE(
		 	$this->get_EventDateValue() 
		, 	$this->get_StartTimeValue() 
		, 	$this->get_EndTimeValue() 
		, 	$this->get_SubjectValue() 
		, 	$this->get_DetailsValue() 
		, 	$this->get_StaffValue() 
		, 	$this->get_ExtraField1Value() 
		, 	$this->get_ExtraField2Value() 
			)";
			
			$qryInserttblCalendar = new MySqlResults($strSql);
		if ($qryInserttblCalendar->result)
		{
			/*Extra post sql processing  */
		}else
			return $this->_setFailScreens("Unable to add to  tblCalendar");
			
		return true;
	}
	}

?>